/* main.c  */

#include "public.h"
#include "parser.h"
#include "scan.h"
#include "tools.h"
#include "code.h"

int lineno = 0;
FILE *src;
FILE *my_test;
FILE *syn_point;
FILE *vari_point;
FILE *tree_tab;
FILE *cfile_ptr;

var_tab *tab_head = NULL;

#define TestScan
#define TestVari

int main(/*int argc, char *argv[]*/)
{
	char src_file[18] = "test_pro.c";
	parser_tree *syn_tree ;                       /* syntax tree */

	src = fopen("test_pro.c", "r");               /* open test programming file */
	if(src == NULL)
	{
		fprintf(stderr, "file %s is not find.\n", src_file);
		exit(1);
	}

	my_test = fopen("scan.tmp", "w+");             /* open a file pointer for sanner         */
	syn_point = fopen("syn_err.err", "w+");        /* open a file pointer for syntax error   */
	vari_point = fopen("vari_tab.tmp", "w+");      /* open a file pointer for varibale table */
	tree_tab = fopen("tree_tab.tmp", "w+");        /* open a file pointer for syntax tree    */
	cfile_ptr = fopen("asm_code.tmp", "w+");       /* open a file pointer for assembly code  */

	syn_tree = parser();                           /* syntax analyze         */
	out_syn_tree(syn_tree);                        /* print syntax tree      */
	code_gene(syn_tree);                           /* generate assembly code */

#ifdef TestVari
	print_variable();
#endif

#ifdef TestScan
	src = fopen("test_pro.c", "r");
	if(my_test == NULL)
	{    fprintf(stderr, "\nopen file error!");        exit(1);}
	while(get_token() != ENDFILE);
#endif

	fclose(src);                      /* close file pointer */
	fclose(my_test);
	fclose(syn_point);
	fclose(vari_point);
	fclose(tree_tab);
	fclose(cfile_ptr);
	free_tree(syn_tree);
	syn_tree = NULL;

	return 0;
}
